<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<s:layout-render name="/layout/normal.jsp">
  <s:layout-component name="body">
  <c:forEach items="${user.timelines}" var="timeline">
    <c:set var="timeline" value="${xp:reload(timeline)}"/>
    <c:set var="curSeg" value="${timeline.currentSegment}"/>
    <c:if test="${!empty timeline.id}">
      <div class="info-box">
        <h3>
          <c:choose>
            <c:when test="${empty curSeg}">
              <s:link beanclass="org.xptracker.web.TimeSegmentsActionBean">
                <s:param name="timelineId" value="${timeline.id}"/>
                ${timeline.name} - {none}
              </s:link>
            </c:when>
            <c:otherwise>
              <s:link beanclass="org.xptracker.web.TimeSegmentActionBean">
                <s:param name="timelineId" value="${timeline.id}"/>
                <s:param name="segmentId" value="${curSeg.id}"/>
                ${timeline.name} - ${curSeg.name}
              </s:link>
            </c:otherwise>
          </c:choose>
        </h3>
        <div style="text-align:center">
          <c:choose>
            <c:when test="${empty curSeg}">
              No current segment
            </c:when>
            <c:otherwise>
              <xp:timeline-chart timeline="${timeline}"/>
            </c:otherwise>
          </c:choose>
        </div>
      </div>
    </c:if>
  </c:forEach>

    <ss:secure roles="editor">
    <div class="info-box">
      <h3>In-Process Stories</h3>
      <ul>
        <xp:owned-stories user="${user}">
          <c:set var="storyOwned" value="true"/>
          <li class="<xp:storyClassName story="${story}"/>">
            <c:if test="${story.state eq 'blocked'}">
              (<strong>blocked</strong>)
            </c:if>
            <xp:story-link story="${story}"/>
              <ul>
              <c:forEach items="${story.tasks}" var="task">
                <c:if test="${!task.complete && user == task.owner}">
                  <li>
                      ${task.summary}
                  </li>
                </c:if>
              </c:forEach>
              </ul>
          </li>
        </xp:owned-stories>
      </ul>
      <c:if test="${!storyOwned}"><em>No stories found.</em></c:if>
    </div>
    </ss:secure>

    <c:if test="${!empty user.bookmarkedStories}">
    <div class="info-box">
      <h3>Bookmarks</h3>
      <ul>
        <c:forEach items="${user.bookmarkedStories}" var="story">
          <li><xp:story-link story="${story}"/></li>
        </c:forEach>
      </ul>
    </div>
    </c:if>

    <c:forEach items="${user.queues}" var="queue">
      <div class="info-box">
        <h3>
          <c:set var="queueStories" value="${xp:getStories(queue)}"/>
          <c:if test="${!empty queueStories}">
            <span style="float:right;">${fn:length(queueStories)} Stories
            <s:link beanclass="org.xptracker.web.PlanningActionBean">
              <s:param name="src" value="${queue.id}"/>
              See All
            </s:link>
            </span>
          </c:if>
          ${queue.name}
        </h3>
        <c:choose>
          <c:when test="${!empty queueStories}">
            <ul>
              <c:forEach items="${xp:sublist(queueStories, 6)}" var="story">
                <li class="<xp:storyClassName story="${story}"/>">
                  <div class="info-box-float">
                    <ss:secure roles="editor">
                      [<s:link beanclass="org.xptracker.web.StoryActionBean" event="AlterState">
                      Grab
                      <s:param name="nextState" value="inProcess"/>
                      <s:param name="storyId" value="${story.id}"/>
                      <s:param name="entry" value="Story accepted."/>
                    </s:link>]
                  </ss:secure>
                  </div> <span style="margin-right: 25px;"><xp:story-link story="${story}"/></span>
                </li>
              </c:forEach>
            </ul>
          </c:when>
          <c:otherwise>
            <em>Queue Empty</em>
          </c:otherwise>
        </c:choose>
      </div>
    </c:forEach>

    <c:forEach items="${user.queries}" var="query">
      <c:if test="${xp:contains(user.homepageQueries, query.name)}">
        <div class="info-box">
          <h3>${query.name}</h3>
          <ul>
            <xp:execute-query query="${query}" var="story">
              <li class="<xp:storyClassName story="${story}"/>">
                <xp:story-link story="${story}"/>
              </li>
            </xp:execute-query>
          </ul>
        </div>                                                       
      </c:if>
    </c:forEach>
    <h3 style="margin:0px 0px 3px 0px;">Recent Activity</h3>
    <table class="blog" cellspacing="0">
      <tbody>
        <xp:blog-entries var="entries" storyVar="story" user="${user}" days="7" limitPerStory="5"
                         limit="${user.blogEntryLimit <= 0 ? 5 : user.blogEntryLimit}">
          <c:set var="entryWritten" value="true"/>
          <tr class="<xp:storyClassName story="${story}"/>">
            <td class="summary">
              <span class="summary-date"><fmt:formatDate value="${entries[0].createdDate}" pattern="yyyy-MM-dd"/></span>
              <c:forEach var="entry" items="${entries}" varStatus="stat">
                <c:if test="${stat.first}">
                  <xp:story-link story="${story}"/>
                </c:if>
              </c:forEach>
              |
              <xp:user-link user="${story.creator}"/>
            </td>
          </tr>
          <tr>
            <td class="entries">
              <c:forEach var="entry" items="${entries}" varStatus="blogStatus">
                <div style="padding: 5px; <c:if test="${!blogStatus.last}">border-bottom: 1px dashed black;</c:if>">
                  <strong>
                    <fmt:formatDate value="${entry.createdDate}" pattern="yyyy-MM-dd @ HH:mm"/>
                  </strong> <xp:user-link user="${entry.creator}"/> :
                  <xp:wiki-display content="${entry.wikiContent}" maxLines="2"/>
                </div>
              </c:forEach>
            </td>
          </tr>
          <tr>
            <td style="padding: 5px;"></td>
          </tr>
        </xp:blog-entries>
      </tbody>
    </table>
  <c:if test="${!entryWritten}"><em>No activity found.</em></c:if>

  </s:layout-component>
</s:layout-render>
